﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;

namespace BLL
{
    public class BrandCateBLL
    {

        public List<BrandCate> GetAll()
        {
            using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
            {
                return data.BrandCates.OrderBy(p => p.BrandCateName).ToList();
            }
        }

        public List<BrandCate> GetByTop(int top, int skip)
        {
            using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
            {
                return data.BrandCates.OrderBy(p => p.CreateDate).Take(top).Skip(skip).ToList();
            }
        }

        public BrandCate GetById(int id)
        {
            using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
            {
                return data.BrandCates.Where(p => p.Id == id).FirstOrDefault();
            }
        }

        
        public void Add(BrandCate obj)
        {
            using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
            {
                data.BrandCates.InsertOnSubmit(obj);
                data.SubmitChanges();
            }
        }
        public void Update(BrandCate Brand)
        {
            using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
            {
                BrandCate obj = data.BrandCates.Where(p => p.Id == Brand.Id).FirstOrDefault();
                if (obj != null)
                {
                    obj.BrandCateName = Brand.BrandCateName;
                    obj.Description = Brand.Description;
                    obj.CreateDate = Brand.CreateDate;
                    obj.Content = Brand.Content;
                    obj.Website = Brand.Website;
                    obj.Image = Brand.Image;
                }
                data.SubmitChanges();
            }
        }
        public void Delete(int id)
        {
            using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
            {
                BrandCate obj = data.BrandCates.Where(p => p.Id == id).FirstOrDefault();
                if (obj != null)
                {
                    data.BrandCates.DeleteOnSubmit(obj);
                    data.SubmitChanges();
                }
            }
        }
    }
}
